
import XEUtils from 'xe-utils';
import { ButtonItem } from "/@/api/admin/button";
import { BUTTON_LIST_KEY, } from '/@/enums/cacheEnum';
import { Persistent } from '/@/utils/cache/persistent';

export const iconSelect = (icon:string) => {
  let href = 'https://icon-sets.iconify.design/'
  if (icon) {
    const arr = icon.split(':')
    if (arr.length > 1) {
      arr.forEach(e => href = `${href}${e}/`)
    }
  }
  return href;
}

export const getCacheButtonList = () => {
  const allButtonList = Persistent.getLocal(BUTTON_LIST_KEY) as ButtonItem[] || []
  return allButtonList
}

export const setCacheButtonList = (buttonList:ButtonItem[]) => {
  Persistent.setLocal(BUTTON_LIST_KEY, buttonList, true)
}

//
export const getCode = (pre:string) => {
  const random = XEUtils.padStart(XEUtils.random(1, 100000), 6, '0')
  const result = `${pre}${XEUtils.toDateString(new Date(), 'yyyyMMdd')}_${random}`
  return result
}

export const genCode = () => {
  const code = `${XEUtils.padStart(XEUtils.random(1, 100), 3, '0')}_${XEUtils.padStart(XEUtils.random(1, 100), 3, '0')}`
  return code
}
